﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GenerateCode.Service
{
    /// <summary>
    /// 修改项目名称
    /// </summary>
    public class RenameService
    {
      
        public RenameService()
        {
           
        }
        /// <summary>
        /// 修改项目名称
        /// </summary>
        /// <param name="name">项目新名称</param>
        public  void Rename (string name)
        {
            string currentPath = Directory.GetCurrentDirectory();
            string rootPath = currentPath.Substring(0, currentPath.LastIndexOf("GenerateCode"));
            Console.WriteLine(rootPath);
            string[] directories = Directory.GetDirectories(rootPath);

            foreach (string directory in directories)
            {
                string directoryName = Path.GetFileName(directory);
                if (directoryName.Contains("GoodDotNet."))
                {
                    string newDirectoryName = directoryName.Replace("GoodDotNet.", @"{name}.");
                    string newDirectoryPath = Path.Combine(rootPath, newDirectoryName);
                    Directory.Move(directory, newDirectoryPath);
                }
            }
        }
    }
}
